#include "Application.hpp"

using namespace Data;

namespace App {
void Application::windowFocused() {}

void Application::keyboardEvent(const KeyboardEvent &event) {
  if (event.key == KeyboardEvent::Key::Escape &&
      event.type == KeyboardEvent::Type::KeyPressed) {
    auto window = glfwGetCurrentContext();
    glfwSetWindowShouldClose(window, 1);
  }
}

void Application::windowSizeChanged(int w, int h) { glViewport(0, 0, w, h); }

void Application::setup() {
  glClearColor(0.f, 0.f, 0.f, 1.f);
  IMGUI_CHECKVERSION();
  ImGui::CreateContext();
  ImGuiIO &io = ImGui::GetIO();
  (void)io;
  ImGui::StyleColorsDark();

  auto window = glfwGetCurrentContext();
  ImGui_ImplGlfw_InitForOpenGL(window, true);
  ImGui_ImplOpenGL3_Init("#version 450 core");
}

void Application::renderEnd() {
  ImGui::Render();
  ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
}

void Application::renderStart() {
  ImGui_ImplOpenGL3_NewFrame();
  ImGui_ImplGlfw_NewFrame();
  ImGui::NewFrame();
  glClear(GL_COLOR_BUFFER_BIT);
}

void Application::render() { onGuiRender(); }

void Application::mouseEvent(const MouseEvent &event) {}

Application::~Application() {
  ImGui_ImplOpenGL3_Shutdown();
  ImGui_ImplGlfw_Shutdown();
  ImGui::DestroyContext();
}

} // namespace App